package Array;

/**
 * Enjoy programming!!!
 * Time: 2021/10/28 -  16:31
 */
public class Triangle {
    public static void main(String[] args) {
        int[][] array = new int[10][];

        for (int i = 0; i < 10; i++)//必须用10，用array[i].length会报错，因为行还没有初始化
            array[i] = new int[i + 1];//n是第i行的个数
        for (int i = 0; i < array.length; i++) {//循环到了第i行

            for (int j = 0; j < array[i].length; j++) {//循环到了第j列
                if (0 == j || array[i].length - 1 == j)
                    array[i][j] = 1;
                else
                    array[i][j] = array[i - 1][j] + array[i - 1][j - 1];
                //               System.out.println(array[i][j] + " ");

            }
        }

        for (int[] row : array) {
            for (int o : row) {
                System.out.printf("%4d", o);
            }
            System.out.println();
        }
    }
}

